package com.jwgf.Half485.fxthreadpool;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.util.ArrayList;

public class FxCommandFeeder {
    public FxCommandFeeder() {

    }

    @Subscribe
    public void onPollingFinished(FxPLCData.FxResult result) {
        if (result.addr == 102) {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            FxCommandManager.getInstance().putNormalCmd(getPollingCmd());
        }
    }

    public void start() {
        EventBus.getDefault().register(this);
        FxCommandManager.getInstance().putPriorityCmd(getInitCmd());
        FxCommandManager.getInstance().putNormalCmd(getPollingCmd());
    }

    private ArrayList<byte[]> getInitCmd() {
        ArrayList<byte[]> cmdList = new ArrayList<byte[]>();
        cmdList.add(FxUtils.createWRCmd(2, 720, 8));
//        cmdList.add(FxUtils.createWRCmd(4, 400, 21));
//        cmdList.add(FxUtils.createWRCmd(5, 409, 8));
//        cmdList.add(FxUtils.createWRCmd(6, 210, 17));
        return cmdList;
    }

    private ArrayList<byte[]> getPollingCmd() {
        ArrayList<byte[]> cmdList = new ArrayList<byte[]>();
        cmdList.add(FxUtils.createWRCmd(2, 102, 15));//15
//        cmdList.add(FxUtils.createWRCmd(4, 300, 23));
//        cmdList.add(FxUtils.createWRCmd(5, 308, 3));
//        cmdList.add(FxUtils.createWRCmd(6, 160, 5));
//        cmdList.add(FxUtils.createWRCmd(6, 166, 3));
//        cmdList.add(FxUtils.createWRCmd(6, 176, 2));
//        cmdList.add(FxUtils.createWRCmd(8, 11, 5));
        return cmdList;
    }
}
